<?php
	App::import('Controller','Eav.AbstractFields');
	class UserFieldsController extends AbstractFieldsController
	{
		var $name = "UserFields";
		
		function admin_add()
		{
			parent::admin_add();
			if(empty($this->data))
			{
				$this->UserField->setFieldProperties('signup',array('checked'=>true));
				$this->UserField->setFieldProperties('edit',array('checked'=>true));
			}
			$this->pageTitle= __("Add");
		}
		
		function admin_updateOrder()
		{
			$ordersString = $_POST['orders'];
			$orders = explode('|',$ordersString);
			$i = 1;
			foreach($orders as $fieldId)
			{
				$fieldId = $this->_getFieldModel()->field('id',array('id'=>$fieldId));
				if($fieldId)
				{
					$this->_getFieldModel()->id = $fieldId;
					$this->_getFieldModel()->saveField('order',$i);
					$i++;
				}
			}
			$this->_stop();
		}
		
		function admin_setOrders()
		{
			$fields = $this->_getFieldModel()->find('all',array('conditions'=>array(),'order'=>"UserField.order ASC"));
			$this->pageTitle = __("Sort User fields");
			$this->set(compact('fields'));
			
		}
		
		function admin_edit($id = null)
		{
			parent::admin_edit($id);
			$this->pageTitle= __("Edit");
		}
	}
?>